<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>科目修改</title>

    <link rel="stylesheet" type="text/css" href="/static/js/layui-v2.5.7/layui/css/layui.css">
    <script type="text/javascript" src="/static/js/layui-v2.5.7/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/myJs.js"></script>

    <script>
        layui.use(['form'], function () {
            var form = layui.form;
        })
    </script>

</head>
<body>

<a href="SelectCourse" class="layui-btn layui-btn-radius layui-btn-primary">
    <i class="layui-icon">&#xe65a;</i>
</a>

<form action="UpdateCourse" method="post" class="layui-form">

    <div class="layui-form-item">
        <div class="layui-input-inlinet">
            <input type="hidden" name="id" value="{$SelectGetCourse.id}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" for="name">科目名字</label>
        <div class="layui-input-inline">
            <input type="text" name="name" id="name" class="layui-input"
                   placeholder="请输入科目名称" required>
        </div>
        <button type="button" onclick="UPdate();" class="layui-btn layui-btn-normal">修改</button>
    </div>
</form>


<script>
    $(function () {
        $.ajax({
            dataType: "json",
            type: "GET",
            url: "/studentLayer/Course/UpdateCourse",
            data: {"id": $("input[name=id]").val()},
            success: function (ajax) {
                if (ajax.code == 0) {
                    var html = ajax.dataAjax.name;
                    console.log(html);
                    $("#name").val(html);

                } else {
                    layer.msg("没有查到数据", function () {
                        window.location.href = "/studentLayer/Course/SelectCourse";
                    });
                }
            }
        })
    })

    function UPdate() {
        $.ajax({
            dataType: "json",
            type: "POST",
            url: "/studentLayer/Course/UpdateCourse",
            data: {
                "id": $("input[name=id]").val(),
                "name": $("#name").val()
            },
            success: function (ajax) {
                if(ajax.code==0){
                    layer.msg(ajax.msg,function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload(index);
                        parent.layer.close(index);
                        window.location.href="/studentLayer/Course/SelectCourse";
                    });

                }else {
                    layer.msg(ajax.msg,function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.location.reload(index);
                        parent.layer.close(index);
                        window.location.href="/studentLayer/Course/SelectCourse";
                    });
                }
            }


        })
    }

</script>


</body>
</html>